package com.cqu.hhx.driver.controller;

import com.cqu.hhx.driver.entity.Customer;
import com.cqu.hhx.driver.entity.Driver;
import com.cqu.hhx.driver.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.sql.Timestamp;

/**
 * @author DJ
 * @create 2020-05-24 21:28
 * 注册控制器
 */
@RestController
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    /**
     * 乘客注册
     * 传入参数：电话，姓名，密码
     * @param customer
     * @return 0:注册成功 1:注册失败，电话号码重复 2:注册失败，未知原因
     */
    @RequestMapping(value = "/customer/register",method = RequestMethod.POST)
    public Integer registerCustomer(@RequestBody Customer customer){
        Timestamp createTime=new Timestamp(System.currentTimeMillis());
        customer.setCreateTime(createTime);
        customer.setAccount(customer.getPhone());
        Integer status=registerService.addCustomer(customer);
        return status;
    }

    /**
     * 司机注册
     * 传入参数：电话，姓名，密码，身份证，驾照编号
     * @param driver
     * @return 0:注册成功 1:注册失败,电话号码重复 2：注册失败，未知原因
     */
    @RequestMapping(value = "/driver/register",method = RequestMethod.POST)
    public Integer registerDriver(@RequestBody Driver driver){
        Timestamp createTime=new Timestamp(System.currentTimeMillis());
        driver.setCreateTime(createTime);
        driver.setAccount(driver.getPhone());
        Integer status=registerService.addDriver(driver);
        return status;
    }

    /**
     * 司机注册
     * 传入参数：电话，姓名，密码，身份证，驾照编号
     * @param phone
     * @param driverName
     * @param passWord
     * @param idCard
     * @param license
     * @return 0:注册成功 1:注册失败,电话号码重复 2：注册失败，未知原因
     */
    @RequestMapping(value = "/driver/android/register",method = RequestMethod.POST)
    public Integer registerDriver(@RequestParam String phone,@RequestParam String driverName,
                                  @RequestParam String passWord,@RequestParam String idCard,
                                  @RequestParam String license){
        Driver driver=new Driver(passWord,driverName,idCard,license,phone);
        Timestamp createTime=new Timestamp(System.currentTimeMillis());
        driver.setCreateTime(createTime);
        driver.setAccount(driver.getPhone());
        Integer status=registerService.addDriver(driver);
        return status;
    }
}
